package www.nomina.controller.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import www.nomina.model.dao.usuariosDao;

/**
 * Servlet implementation class homeSVR
 */
@WebServlet(name = "HOME", urlPatterns = { "/commonsSVR" })
public class commonsSVR extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private String mapping = "/VIEW/COMMONS/index.jsp";

	usuariosDao usrDao = new usuariosDao();

	public commonsSVR() {
		super();
		System.out.println("HOME SVR EN EJECUCION");
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		System.out.println("SVR.home----------> doGet");
		mapping = "/VIEW/COMMONS/index.jsp";
		request.getRequestDispatcher(mapping).forward(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		System.out.println("SVR.home----------> doPost");
		int dispatch = Integer.parseInt(request.getParameter("dispatch"));

		try {
			switch (dispatch) {
			case 1:// INDEX
				mapping = "VIEW/COMMONS/index.jsp";
				break;
			case 2:// REGISTRO
				mapping = "VIEW/COMMONS/registro.jsp";
				break;
			case 3:// RESET
				mapping = "VIEW/COMMONS/reset.jsp";
				break;
			}

		} catch (Exception error) {
			request.setAttribute("mensaje", error.getMessage());
			mapping = "/VIEW/COMMONS/index.jsp";
		} finally {
			request.getRequestDispatcher(mapping).forward(request, response);
		}
	}

}
